package com.zhejiangzhengyuan.municipal_common.entity.vo;

import com.zhejiangzhengyuan.municipal_common.entity.DeviceMonitorValue;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;

/**
 * @author ZhouXiang
 * @since on 2020/1/3
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "设备阈值获取针对多级警告使用", description = "区分多级警告")
public class DeviceMonitorValueVo {

  @ApiModelProperty(value = "自增主键")
  private Long id;

  @ApiModelProperty(value = "轮询时间")
  private String polling;

  @ApiModelProperty(value = "报警状态")
  private String warnStatus;

  @ApiModelProperty(value = "声音")
  private Boolean sound;

  @ApiModelProperty(value = "一级阈值")
  private Integer warnValue1;

  @ApiModelProperty(value = "二级阈值")
  private Integer warnValue2;

  @ApiModelProperty(value = "三级阈值")
  private Integer warnValue3;

  @ApiModelProperty(value = "系统类型")
  private String moduleType;

  public static DeviceMonitorValueVo formatVo(List<DeviceMonitorValue> deviceMonitorValues) {
    DeviceMonitorValueVo result = new DeviceMonitorValueVo();
    for (DeviceMonitorValue deviceMonitorValue : deviceMonitorValues) {
      switch (deviceMonitorValue.getGrade()) {
        case "一级":
          result.setWarnValue1(deviceMonitorValue.getWarnValue());
          break;
        case "二级":
          result.setWarnValue2(deviceMonitorValue.getWarnValue());
          break;
        case "三级":
          result.setWarnValue3(deviceMonitorValue.getWarnValue());
          break;
      }
    }
    DeviceMonitorValue deviceMonitorValue = deviceMonitorValues.get(0);
    result
        .setModuleType(deviceMonitorValue.getModuleType())
        .setPolling(deviceMonitorValue.getPolling())
        .setSound(deviceMonitorValue.getSound())
        .setWarnStatus(deviceMonitorValue.getWarnStatus());

    return result;
  }

  public static List<DeviceMonitorValue> formatPo(
      DeviceMonitorValueVo deviceMonitorValueVo, String moduleType) {
    List<DeviceMonitorValue> result = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
      DeviceMonitorValue deviceMonitorValue =
          new DeviceMonitorValue()
              .setModuleType(moduleType)
              .setSound(deviceMonitorValueVo.getSound())
              .setWarnStatus(deviceMonitorValueVo.getWarnStatus())
              .setPolling(deviceMonitorValueVo.getPolling());
      switch (i) {
        case 0:
          deviceMonitorValue.setGrade("一级").setWarnValue(deviceMonitorValueVo.getWarnValue1());
          break;
        case 1:
          deviceMonitorValue.setGrade("二级").setWarnValue(deviceMonitorValueVo.getWarnValue2());
          break;
        case 2:
          deviceMonitorValue.setGrade("三级").setWarnValue(deviceMonitorValueVo.getWarnValue3());
          break;
      }
      result.add(deviceMonitorValue);
    }
    return result;
  }
}
